//
//  CLNetworkingTools.swift
//  WeiBo
//
//  Created by 程雷 on 2017/1/6.
//  Copyright © 2017年 chenglei. All rights reserved.
//

import UIKit
import AFNetworking

enum HTTPMethod: Int {
    case GET
    case PUT
}

class CLNetworkingTools: AFHTTPSessionManager {
    
    static let shared: CLNetworkingTools = {
        
        let tools = CLNetworkingTools(baseURL: nil)
        
        return tools
        
    }()
    
    
    func request(method: HTTPMethod, url: String, parameters: Any?, completed: @escaping (Any?,Error?) -> ()){
        
        if method == .GET{
           
            self.get(url, parameters: nil, progress: nil, success: { (task: URLSessionDataTask, res: Any?) in
                
                completed(res, nil)
                
            }, failure: { (task :URLSessionDataTask?, error: Error) in
                
                completed(nil, error)
            })

            
        }else{
            
            self.post(url, parameters: nil, progress: nil, success: { (task :URLSessionDataTask, res :Any?) in
                
                completed(res, nil)
                
            }, failure: { (task :URLSessionDataTask?, error: Error) in
                
                completed(nil,error)
            })
            
        }

        
    }
}
